/*
 * Copyright 2025 The Android BYOD Project
 */

package com.example.testble;

/**
 * ByodLogger is a singleton utility class for initializing and globally accessing an ILogger
 * instance. It also provides convenient logging methods.
 */
public final class BLogger {
    private static volatile ILogger logger;

    // Private constructor to prevent instantiation
    private BLogger() {}

    /**
     * Initializes the logger instance.
     *
     * @param loggerInstance the specific implementation of ILogger
     * @throws IllegalArgumentException if loggerInstance is null
     */
    public static void init(ILogger loggerInstance) {
        if (loggerInstance == null) {
            throw new IllegalArgumentException("loggerInstance cannot be null");
        }
        synchronized (BLogger.class) {
            logger = loggerInstance;
        }
    }

    /**
     * Retrieves the ILogger instance.
     *
     * @return the initialized ILogger instance
     * @throws IllegalStateException if the logger has not been initialized
     */
    private static ILogger getLogger() {
        if (logger == null) {
            throw new IllegalStateException("Logger not initialized. Please call init() first.");
        }
        return logger;
    }

    /**
     * Logs a verbose message.
     *
     * @param tag the tag identifying the source of the log message
     * @param message the message(s) to log
     */
    public static void v(String tag, String... message) {
        getLogger().v(tag, message);
    }

    /**
     * Logs a debug message.
     *
     * @param tag the tag identifying the source of the log message
     * @param message the message(s) to log
     */
    public static void d(String tag, String... message) {
        getLogger().e(tag, message);
    }

    /**
     * Logs an informational message.
     *
     * @param tag the tag identifying the source of the log message
     * @param message the message(s) to log
     */
    public static void i(String tag, String... message) {
        getLogger().e(tag, message);
    }

    /**
     * Logs a warning message.
     *
     * @param tag the tag identifying the source of the log message
     * @param message the message(s) to log
     */
    public static void w(String tag, String... message) {
        getLogger().w(tag, message);
    }

    /**
     * Logs an error message.
     *
     * @param tag the tag identifying the source of the log message
     * @param message the message(s) to log
     */
    public static void e(String tag, String... message) {
        getLogger().e(tag, message);
    }
}
